package com.lwj.liwanjia.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.lwj.liwanjia.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/9/15.
 */

public class RecordImageAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater inflater;
    private List<String> list;

    public RecordImageAdapter(Context mContext, List<String> list) {
        this.mContext = mContext;
        this.list = list;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.record_item1, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Glide.with(mContext).load(list.get(position)).error(R.mipmap.tupian).into(holder.ivShangpin);
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.iv_shangpin)
        ImageView ivShangpin;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
